package com.ruoyi.slope.device.deviceInfo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.slope.dataFile.domain.SlopeDataFile;
import com.ruoyi.slope.dataFile.service.ISlopeDataFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.slope.device.deviceInfo.domain.SlopeDeviceInfo;
import com.ruoyi.slope.device.deviceInfo.service.ISlopeDeviceInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备列表Controller
 * 
 * @author psy
 * @date 2025-05-10
 */
@RestController
@RequestMapping("/device/deviceInfo")
public class SlopeDeviceInfoController extends BaseController
{    
    @Autowired
    private ISlopeDataFileService slopeDataFileService;
    @Autowired
    private ISlopeDeviceInfoService slopeDeviceInfoService;

    /**
     * 查询设备列表列表
     */
    @PreAuthorize("@ss.hasPermi('device:deviceInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlopeDeviceInfo slopeDeviceInfo)
    {
        startPage();
        List<SlopeDeviceInfo> list = slopeDeviceInfoService.selectSlopeDeviceInfoList(slopeDeviceInfo);
        return getDataTable(list);
    }

    /**
     * 查询设备列表列表
     */
    @PreAuthorize("@ss.hasPermi('device:deviceInfo:list')")
    @GetMapping("/listSn")
    public String[] listSn(SlopeDeviceInfo slopeDeviceInfo)
    {
        slopeDeviceInfo.setDeptId(getDeptId());
        return slopeDeviceInfoService.selectSlopeDeviceSnList(slopeDeviceInfo);
    }

    /**
     * 导出设备列表列表
     */
    @PreAuthorize("@ss.hasPermi('device:deviceInfo:export')")
    @Log(title = "设备列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlopeDeviceInfo slopeDeviceInfo)
    {
        List<SlopeDeviceInfo> list = slopeDeviceInfoService.selectSlopeDeviceInfoList(slopeDeviceInfo);
        ExcelUtil<SlopeDeviceInfo> util = new ExcelUtil<SlopeDeviceInfo>(SlopeDeviceInfo.class);
        String path = util.exportExcel(response, list, "设备列表数据");
        SlopeDataFile slopeDataFile = new SlopeDataFile();
        slopeDataFile.setFileName(path);
        slopeDataFileService.insertSlopeDataFile(slopeDataFile);
    }

    /**
     * 获取设备列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('device:deviceInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(slopeDeviceInfoService.selectSlopeDeviceInfoById(id));
    }

    /**
     * 新增设备列表
     */
    @PreAuthorize("@ss.hasPermi('device:deviceInfo:add')")
    @Log(title = "设备列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlopeDeviceInfo slopeDeviceInfo)
    {
        return toAjax(slopeDeviceInfoService.insertSlopeDeviceInfo(slopeDeviceInfo));
    }

    /**
     * 修改设备列表
     */
    @PreAuthorize("@ss.hasPermi('device:deviceInfo:edit')")
    @Log(title = "设备列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlopeDeviceInfo slopeDeviceInfo)
    {
        return toAjax(slopeDeviceInfoService.updateSlopeDeviceInfo(slopeDeviceInfo));
    }

    /**
     * 删除设备列表
     */
    @PreAuthorize("@ss.hasPermi('device:deviceInfo:remove')")
    @Log(title = "设备列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(slopeDeviceInfoService.deleteSlopeDeviceInfoByIds(ids));
    }
}
